package dt.member;

import java.io.IOException;
import java.io.Reader;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class memberDeleteAction extends ActionSupport {
	
	public static Reader reader;  // ���� ��Ʈ���� ���� reader
	public static SqlMapClient sqlMapper; // SqlMapClient API�� ����ϱ� ���� sqlMapper ��ü

	private memberVO paramClass;  // �Ķ���͸� ������ ��ü
	private memberVO resultClass; // ���� ��� ���� ������ ��ü
	
	private String id;
	private String passwd;
	private int deleteCheck;
	
	//����
	public memberDeleteAction() throws IOException {
		reader = Resources.getResourceAsReader("sqlMapConfig.xml"); //sqlMapConfig.xml ������ ���������� �����´�.
		sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader); //sqlMapConfig.xml ������ ����� sqlMapper ��ü ��
		reader.close();
	}
	
	public String execute() throws Exception {
		
		// �Ķ���Ϳ� ����Ʈ ��ü ��
		paramClass = new memberVO();
		resultClass = new memberVO();
		
		//�ش� ���̵��� ������ �����´�
		id = ActionContext.getContext().getSession().get("id").toString();
		resultClass = (memberVO) sqlMapper.queryForObject("getMember", getId());
		
		if(resultClass.getPasswd().equals(passwd)) {
			//�н����尡 ������
			deleteCheck = 1;
			//������ �׸� ����
			paramClass.setId(getId());
			//���� ���� ����
			sqlMapper.update("deleteMember", paramClass);
			ActionContext.getContext().getSession().clear();
		}
		else {
			deleteCheck = -1; //�н����尡 �ȸ�����
		}
		return SUCCESS;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public static Reader getReader() {
		return reader;
	}

	public static void setReader(Reader reader) {
		memberDeleteAction.reader = reader;
	}

	public static SqlMapClient getSqlMapper() {
		return sqlMapper;
	}

	public static void setSqlMapper(SqlMapClient sqlMapper) {
		memberDeleteAction.sqlMapper = sqlMapper;
	}

	public memberVO getParamClass() {
		return paramClass;
	}

	public void setParamClass(memberVO paramClass) {
		this.paramClass = paramClass;
	}

	public memberVO getResultClass() {
		return resultClass;
	}

	public void setResultClass(memberVO resultClass) {
		this.resultClass = resultClass;
	}

	public String getPasswd() {
		return passwd;
	}

	public void setPasswd(String passwd) {
		this.passwd = passwd;
	}

	public int getDeleteCheck() {
		return deleteCheck;
	}

	public void setDeleteCheck(int deleteCheck) {
		this.deleteCheck = deleteCheck;
	}
	
}
